﻿using System;
using System.IO;
using PTop.Code.Image;

namespace PTop.Domain.Entity.Biz
{
    /// <summary>
    /// 附件信息Entity
    /// </summary>	
    public class AttachmentEntity : IEntity<AttachmentEntity>, ICreationAudited
    {

        /// <summary>
        /// 编号
        /// </summary>
        public string F_Id { get; set; }
        /// <summary>
        /// 类别。1=文章标题图片,2=文章内容图片,3=用户意见建议图片
        /// </summary>
        public string F_Type { get; set; }
        /// <summary>
        /// F_Name
        /// </summary>
        public string F_Name { get; set; }
        /// <summary>
        /// F_Suffix
        /// </summary>
        public string F_Suffix { get; set; }
        /// <summary>
        /// F_Size
        /// </summary>
        public long F_Size { get; set; }
        /// <summary>
        /// F_Path
        /// </summary>
        public string F_Path { get; set; }
        /// <summary>
        /// F_ThumbPath
        /// </summary>
        public string F_ThumbPath { get; set; }
        /// <summary>
        /// 创建者
        /// </summary>
        public string F_CreatorUserId { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? F_CreatorTime { get; set; }

        public void MakeThumbnail()
        {
            F_ThumbPath = F_Path + "!60X60";
            ImageOperation.MakeThumbnail(F_Path, F_ThumbPath, 60, 60);
            ImageOperation.MakeThumbnail(F_Path, F_Path + "!200", 200);
        }

        public string GetFilePath(string baseLoation)
        {
            var filepath = baseLoation + "/" + F_Type + "/" + DateTime.Now.ToString("yyyyMM");
            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }
            var fileFullName = Path.Combine(filepath, F_Name + F_Suffix);
            return fileFullName;
        }

        public string GetWebPath(string basePath)
        {
            var filepath = basePath + "/" + F_Type + "/" + DateTime.Now.ToString("yyyyMM");
            var webPath = filepath + "/" + F_Name + F_Suffix;
            return webPath;
        }
    }
}